/**
 * 应用 Store Composable
 * 统一管理 store 实例，避免重复创建
 */
import { storeToRefs } from "pinia";
import { useAppSettings } from "@/Stores/appSettings";

/**
 * 使用应用配置 Store
 * @returns {Object} { store, appSettings, systemTheme }
 */
export function useAppStore() {
  const store = useAppSettings();
  const { appSettings, systemTheme } = storeToRefs(store);

  /**
   * 更新应用设置
   * @param {Object} settings - 设置对象
   */
  const updateAppSettings = (settings) => {
    store.setAppSettings(settings);
  };

  /**
   * 切换菜单展开状态
   */
  const toggleMenuExpand = () => {
    appSettings.value.menuIsExpand = !appSettings.value.menuIsExpand;
    updateAppSettings(appSettings.value);
  };

  return {
    store,
    appSettings,
    systemTheme,
    updateAppSettings,
    toggleMenuExpand,
  };
}
